﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using NGuestBook.Entity;

namespace NGuestBook.AccessDAL
{
    /**//// <summary>
    /// DataReader到实体类的转换策略-管理员
    /// 实现上使用Singleton模式，保证全局唯一实例
    /// </summary>
    public class AdminDataReaderToEntityStrategy : IDataReaderToEntityStrategy<AdminInfo>
    {
        private static AdminDataReaderToEntityStrategy singleInstance = null;

        /**//// <summary>
        /// 私有化构造函数，保证无法外部实例化
        /// </summary>
        private AdminDataReaderToEntityStrategy() { }

        /**//// <summary>
        /// 静态方法，用于取得全局唯一实例
        /// </summary>
        /// <returns>全局唯一实例</returns>
        public static AdminDataReaderToEntityStrategy GetInstance()
        {
            if (singleInstance == null)
            {
                singleInstance = new AdminDataReaderToEntityStrategy();
            }

            return singleInstance;
        }

        /**//// <summary>
        /// 由DataReader转换到管理员实体类
        /// </summary>
        /// <param name="dataReader">包含数据的DataReader对象</param>
        /// <returns>管理员实体类</returns>
        public AdminInfo DataReaderToEntity(OleDbDataReader dataReader)
        {
            AdminInfo admin = new AdminInfo();
            admin.ID = (int)dataReader["ID"];
            admin.Name = (string)dataReader["Name"];
            admin.Password = (string)dataReader["Password"];

            return admin;
        }
    }
}